/*
    Android UIML

	Copyright (C) 2010  Bram Goffings (bramgoffings@gmail.com)

	This program is free software; you can redistribute it and/or
	modify it under the terms of the GNU Lesser General Public License
	as published by the Free Software Foundation; either version 2.1
	of	the License, or (at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU Lesser General Public License for more details.

	You should have received a copy of the GNU Lesser General Public License
	along with this program; if not, write to the Free Software
	Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

package uiml.android.RenderTools;

import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;

public class LayoutUtils {

	/**
	 * 
	 * @param v
	 * @param h
	 */
	public static void setLayoutHeight(View v, int h){
		
		int width =0;
		
		ViewGroup.LayoutParams params = (LayoutParams)v.getLayoutParams();
		
		if(params != null)
			width = params.width;	
		
		v.setLayoutParams(new ViewGroup.LayoutParams(width, h));	
	}
	
	/**
	 * 
	 * @param v
	 * @param w
	 */
	public static void setLayoutWidth(View v, int w){
		
		int h = 0;
		
		ViewGroup.LayoutParams params = (ViewGroup.LayoutParams)v.getLayoutParams();
		
		if(params != null)
			h = params.height;
		
		v.setLayoutParams(new ViewGroup.LayoutParams(w, h));	
	}
	
	/**
	 * 
	 * @param v
	 * @param h
	 * @param w
	 */
	public static void setLayoutWidthAndHeight(View v, int h, int w){
		v.setLayoutParams(new ViewGroup.LayoutParams(h, w));	
	}

	
	/**
	 * 
	 * @param view
	 * @param left
	 * @param top
	 * @param right
	 * @param bottom
	 */
	public static void setLayoutMargins(View view, int left, int top, int right, int bottom) {

		int width=0;
		int height=0;
		
		ViewGroup.LayoutParams params = (LayoutParams)view.getLayoutParams();
		if(params != null) {
			width = params.width;	
			height = params.height;
		}
		
		ViewGroup.MarginLayoutParams marginParams = new ViewGroup.MarginLayoutParams(width, height);
		marginParams.setMargins(left, top, right, bottom);
		
		view.setLayoutParams(marginParams);	
	}
	
}
